//
//  Network+Extension.swift
//

import Foundation

extension Dictionary {
    
    /// 字典先排序，再拼接字符串
    var dictToSortedString: String {
        var sortParams = "{"
        if let params = self as? [String: Any] {
            let sortArr = params.sorted { return $0.0 < $1.0 }
            for (index, value) in sortArr.enumerated() {
                if index == sortArr.count - 1 {
                    sortParams.append("\"\(value.key)\":\"\(value.value)\"")
                } else {
                    sortParams.append("\"\(value.key)\":\"\(value.value)\",")
                }
            }
        }
        sortParams.append("}")
        return sortParams
    }
}
